/**
 * 短信发送审计日志模型
 * 记录所有政采云业务短信的发送情况
 */
module.exports = app => {
  const { STRING, TEXT, BOOLEAN, INTEGER, DATE } = app.Sequelize;

  return app.model.define('sms_audit', {
    business_type: {
      type: STRING(32),
      allowNull: false,
      comment: '业务类型: PRICE_ALERT-价格预警, BLACKLIST_NOTICE-黑名单通知'
    },
    phone_numbers: {
      type: TEXT,
      allowNull: false,
      comment: '加密存储的接收手机号列表'
    },
    template_code: {
      type: STRING(32),
      allowNull: false,
      comment: '短信模板CODE'
    },
    params: {
      type: TEXT,
      comment: '短信模板参数JSON'
    },
    send_result: {
      type: TEXT,
      comment: '发送结果JSON'
    },
    success: {
      type: BOOLEAN,
      allowNull: false,
      defaultValue: false,
      comment: '是否发送成功'
    },
    operator_id: {
      type: INTEGER,
      comment: '操作人ID'
    },
    created_at: {
      type: DATE,
      defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
      comment: '发送时间'
    }
  }, {
    tableName: 'sms_audit',
    timestamps: false,
    indexes: [
      { fields: ['business_type'] },
      { fields: ['success'] },
      { fields: ['created_at'] },
      { fields: ['operator_id'] }
    ]
  });
};